﻿using System;
using System.Xml.Serialization;
using TheDealmap.Enum;

namespace TheDealmap
{
    [Serializable()]
    [XmlRoot("AddDealRequest", IsNullable = false, Namespace = "http://thedealmap.com/api")]
    public class ProposedDeal
    {
        private CenterdActivity _centerdActivity = CenterdActivity.Unknown;
        private bool? _isExclusive = false;
        private bool? _dailyDealsEmailOK = false;
        private int? _dealSource = 0;
        private bool? _isOwner = false;
        private DateTime? _effectiveDate;
        private DateTime? _expirationDate;
        private double? _latitude;
        private double? _longitude;

        /// <summary>
        /// Initializes a new instance of the <see cref="ProposedDeal"/> class. 
        /// Used to enable serialization when using another constructor.
        /// </summary>
        public ProposedDeal(){}


        /// <summary>
        /// Initializes a new instance of the <see cref="ProposedDeal"/> class.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="expirationDate">The expiration date.</param>
        /// <param name="addedBy">The added by.</param>
        /// <param name="businessName">Name of the business.</param>
        /// <param name="country">The country.</param>
        /// <param name="city">The city.</param>
        /// <param name="state">The state.</param>
        /// <param name="streetAddress">The street address.</param>
        public ProposedDeal(
            string title, 
            DateTime expirationDate, 
            string addedBy, 
            string businessName, 
            string country, 
            string city, 
            string state, 
            string streetAddress
            )
        {
            Title = title;
            ExpirationDate = expirationDate;
            AddedBy = addedBy;
            BusinessName = businessName;
            Country = country;
            City = city;
            State = state;
            StreetAddress = streetAddress;
        }


        /// <summary>
        /// Unique ID for your deal.
        /// </summary>
        /// <remarks>
        /// If you want a persistent ID for your deal (which enables you to update etc) - fill in this element.
        /// </remarks>
        [XmlElement(IsNullable = true)]
        public string ID { get; set; }


        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        [XmlElement(IsNullable = true)]
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the details.
        /// </summary>
        /// <value>The details.</value>
        [XmlElement(IsNullable = true)]
        public string Details { get; set; }

        /// <summary>
        /// Gets or sets the restrictions.
        /// </summary>
        /// <value>The restrictions.</value>
        [XmlElement(IsNullable = true)]
        public string Restrictions { get; set; }

        /// <summary>
        /// Gets the formatted date the deal will start. Note; this property is readonly.
        /// </summary>
        [XmlElement("EffectiveDate", IsNullable = true)]
        public string FormattedDateStart
        {
            get
            {
                 return _effectiveDate.GetValueOrDefault().ToString("s");
            }
            set
            {
                //throw new NotSupportedException("Property is readonly");
            }
        }

        /// <summary>
        /// Gets or sets the effective date.
        /// </summary>
        /// <value>The effective date.</value>
        [XmlIgnore]
        public DateTime? EffectiveDate
        {
            get
            {
                return _effectiveDate;
            }
            set
            {
                _effectiveDate = value;
            }
        }
        /// <summary>
        /// Gets the formatted date the deal will expire. Note; this property is readonly.
        /// </summary>
        [XmlElement("ExpirationDate", IsNullable = true)]
        public string FormattedDateEnd
        {
            get
            {
                return _expirationDate.GetValueOrDefault().ToString("s");
            }
            set
            {
                //throw new NotSupportedException("Property is read only");
            }
        }

        /// <summary>
        /// Gets or sets the expiration date.
        /// </summary>
        /// <value>The expiration date.</value>
        [XmlIgnore]
        public DateTime? ExpirationDate
        {
            get
            {
                return _expirationDate;
            }
            set
            {
                _expirationDate = value;
            }
        }

        /// <summary>
        /// More info link
        /// </summary>
        /// <remarks>
        /// Typically links to your website from The Dealmap.
        /// </remarks>
        [XmlElement(IsNullable = true)]
        public string Url { get; set; }

        /// <summary>
        /// Gets the formatted IsExclusive. Note: This property is readonly.
        /// </summary>
        /// <value>The formatted is exclusive.</value>
        [XmlElement("IsExclusive", IsNullable = false)]
        public int FormattedIsExclusive
        {
            get
            {
                return (_isExclusive.GetValueOrDefault(false))? 1: 0;
            }
            set
            {
              
            }
        }

        /// <summary>
        /// Gets or sets the is exclusive.
        /// </summary>
        /// <value>The is exclusive.</value>
        [XmlIgnore]
        public bool? IsExclusive
        {
            get
            {
                return _isExclusive;
            }
            set
            {
                _isExclusive = value;
            }
        }

        /// <summary>
        /// First name of the contact person for the deal.
        /// </summary>
        /// <remarks>
        /// Not displayed or distributed on the Dealmap. 
        /// </remarks>
        [XmlElement(IsNullable = true)]
        public string FirstName { get; set; }

        /// <summary>
        /// Last name of the contact person for the deal.
        /// </summary>
        /// <remarks>
        /// Not displayed or distributed on the Dealmap. 
        /// </remarks>
        [XmlElement(IsNullable = true)]
        public string LastName { get; set; }

        /// <summary>
        /// Gets or sets the is owner.
        /// </summary>
        /// <value>The is owner.</value>
        [XmlElement(IsNullable = true)]
        public bool? IsOwner
        {
            get
            {
                return _isOwner;
            }
            set
            {
                _isOwner = value;
            }
        }

        /// <summary>
        /// This is the email address of the person that's submitting the deal.
        /// </summary>
        /// <remarks>
        /// Email address is not displayed or distributed by The Dealmap; only used by The Dealmap team to communicate with the submitter when needed. 
        /// </remarks>
        [XmlElement(IsNullable = true)]
        public string AddedBy { get; set; }

        /// <summary>
        /// Facebook ID of the submitter.  
        /// </summary>
        /// <remarks>Only if you want The Dealmap Points and if you have connected your FB account with The Dealmap.</remarks>
        [XmlElement("SocailNetworkID", IsNullable = true)]
        public string SocialNetworkID { get; set;}

        /// <summary>
        /// Gets the formatted value of DailyDealsEmail. Note: The property is readonly.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public bool? DailyDealsEmailOK
        {
            get
            {
                return _dailyDealsEmailOK;
            }
            set
            {
                
            }
        }
        
        /// <summary>
        /// The address of the deal.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string StreetAddress { get; set; }

        /// <summary>
        /// Gets the formatted value of Longitude. Note: The property is readonly.
        /// </summary>
        [XmlElement("Latitude", IsNullable = true)]
        public string FormattedGeoLatitude
        {
            get
            {
                return _latitude.GetValueOrDefault().ToString("#");//+0.000000;-0.000000;
            }

            set
            {

            }
        }

        /// <summary>
        /// /// Gets the formatted value of Longitude. Note: The property is readonly.
        /// </summary>
        [XmlElement("Longitude", IsNullable = true)]
        public string FormattedGeoLongitude
        {
            get
            {
                return _longitude.GetValueOrDefault().ToString("#");//+0.000000;-0.000000;
            }
            set
            {

            }
        }

        /// <summary>
        /// Gets or sets the latitude.
        /// </summary>
        /// <value>The latitude.</value>
        [XmlIgnore]
        public double? Latitude
        {
            get
            {
                return _latitude;
            }
            set
            {
                _latitude = value;
            }
        }

        /// <summary>
        /// Gets or sets the longitude.
        /// </summary>
        /// <value>The longitude.</value>
        [XmlIgnore]
        public double? Longitude
        {
            get
            {
                return _longitude;
            }
            set
            {
                _longitude = value;
            }
        }

        /// <summary>
        /// The city of the deal.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string City { get; set; }

        /// <summary>
        /// The State of the deal.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string State { get; set; }

        /// <summary>
        /// The country of the deal.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string Country { get; set; }

        /// <summary>
        /// Name of the business that is offering the deal. 
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string BusinessName { get; set; }

        /// <summary>
        /// Gets or sets the business details.
        /// </summary>
        /// <value>The business details.</value>
        [XmlElement(IsNullable = true)]
        public string BusinessDetails { get; set; }

        /// <summary>
        /// Extension of the image jpg, png etc.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string PhotoType { get; set; }

        /// <summary>
        /// Base64 encoded image data. 
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string PhotoContent { get; set; }

        /// <summary>
        /// Comma seperated keywords that enables searchig for your deal.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string Tags { get; set; }

        /// <summary>
        /// Category of the deal.
        /// </summary>
        /// <remarks>
        /// Usually YP categoryg E.g: Restaurant, Pharmacy etc.
        /// </remarks>
        [XmlElement(IsNullable = true)]
        public string Category { get; set; }

        /// <summary>
        /// Gets the formatted value of CenterdActivity. Note: The property is readonly.
        /// </summary>
        /// <value>The formatted centerd activity.</value>
        [XmlElement("Styles", IsNullable = true)]
        public int? FormattedCenterdActivity
        {
            get
            {
                return (int)_centerdActivity;
            }
            set
            {
                //required for Serializer to work.
            }
        }

        /// <summary>
        /// Gets or sets the CenterdActivity.
        /// </summary>
        /// <value>The single or Bitwise CenterdActivity</value>
        [XmlIgnore]
        public CenterdActivity CenterdActivity
        {
            get { return _centerdActivity;}
            set { _centerdActivity = value; }
        }

        /// <summary>
        /// Gets or sets the vendor id.
        /// </summary>
        /// <value>The vendor id.</value>
        [XmlElement(IsNullable = true)]
        public string VendorId { get; set;}

        /// <summary>
        /// Gets or sets the deal source.
        /// </summary>
        /// <value>The deal source.</value>
        [XmlElement(IsNullable = true)]
        public int? DealSource
        {
            get
            {
                return _dealSource;
            }
            set
            {
                _dealSource = value;
            }
        }
    }
}
